package com.zhika.zishi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhika.zishi.R;
import com.zhika.zishi.beans.SearchBean;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/20.
 */
public class SearchAdapter extends BaseAdapter {

    private Context context;

    private ArrayList<SearchBean> searchList;

    public SearchAdapter(Context context,ArrayList<SearchBean> searchList){
        this.context = context;

        this.searchList = searchList;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public int getCount() {
        return searchList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;

        if (convertView == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_of_search,null);
            holder = new ViewHolder();
            holder.contentText = (TextView) view.findViewById(R.id.item_of_search_content_text);
            holder.answerTypeText = (TextView) view.findViewById(R.id.item_of_search_answer_type_text);

            view.setTag(holder);
        }else {
            view = convertView;
            holder = (ViewHolder) view.getTag();
            resetViewHolder(holder);
        }

        SearchBean bean = searchList.get(position);
        holder.contentText.setText(bean.getContentTitle());
        holder.answerTypeText.setText(bean.getAnswerType());

        return view;
    }

    private void resetViewHolder(ViewHolder holder){
        holder.contentText.setText(null);
        holder.answerTypeText.setText(null);
    }
    private class ViewHolder{
        private TextView contentText;

        private TextView answerTypeText;
    }
}
